import Vue from "vue"
import Router from "vue-router"
// import store from '@/store/index'
import {docIndexChildren} from './docIndexChildren'
Vue.use(Router)
//在路由跳转的时候同一个路由多次添加是不被允许的
//重写路由的push方法
const VueRouterPush = Router.prototype.push
Router.prototype.push = function push (to) {
    return VueRouterPush.call(this, to).catch(err => err)
}


export const routes = [
    {
    path: '/',
    redirect: '/layout/docIndex/watchComputer'
},
 {
    path: '/login',
    component: () => import('@/pages/login/index.vue')
},
{
    path: '/layout',
    name: 'layout',
    component: () => import('@/components/Layout/index.vue'),
    children: [
      
        {
            path: 'docIndex',
            name: 'docIndex',
            component: () => import ('@components/DOC/index.vue'),
            children: docIndexChildren
        },
        {
            path: 'docDetail',
            name: 'docDetail',
            component: () => import ('@components/DOC/docDetail.vue'),
            children: []  
        }
    ]
}]



let router = new Router({
    routes,
    // mode: 'history' // 默认是hash
})

// router.beforeEach((to, from, next) => {
//     if (to.path !== '/login') {
//         next('/login')
//     }else{
//         next()
//     }
    
// })

// 使用路由守卫
// router.beforeEach((to, from, next) => {
// let { needLogin } = to.meta
// let { isLogin } = store.state

// document.title = title;
//判断，如果不是登录，且要跳转的页面需要登录的时候，我们是先需要跳转到登录页面的
// if (needLogin && !isLogin && to.path !== '/logRe/login') {
//     next({
//         path: "/logRe/login"
//     })

// } else {
//     next()
// }
// })
/* router.afterEach((to,from)=>{
    
    document.title = to.meta.title || "稻草人vue2官网"
}) */

export default router;